﻿using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

//능력치ID	능력치 이름
//		16	HP
//		17	방어도
//		18	저항력
//		19	우선권
//		20	공격타입
//		21	공격력
//		22	치명타 보정
//		23	주목도
//		24	공격 호응도
//		25	방어 호응도

public enum AptitudeID
{
	HP = 16,
	Def,
	Res,
	Prior,
	AtkType,
	Atk,
	Cri,
	Taunt,
	SupportAtk,
	SupportDef,
}

public enum AptitudeID_New
{
    atkType = 16,
    baseAtk,
    growAtk,
    assist,
    baseHP,
    growHP,
    baseDef,
    growDef,
    init,
    taunt,
    melee,
    growMelee,
    range,
    growRange,
    magic,
    growMagic,
    pulse,
    growPulse,
    special,
    growSpecial,
    evade,
    evadeMod,
    defDamage,
    defDamageMod,
    HPMod,
    healRate,
    res,
    skillRate,
    skillRateMod,
    critRate,
    critPower,
    attackAssist,
    defAssist,
    atkInit,
    atkCooltime,
    atkCooltimeMod,
    moveTime,
    moveTimeMod,
    getFromAtk,
    getFromHit,
    moveSpd,
    moveSpdMod,
    healPower,
    healPowerMod
}

public class MemberModel
{
    public int no;
    public int id;
    public string name; // 이름
    public short level  //; // 레벨  
    {
        get { return m_level;}
        set
        {
            m_level = value;
            maxTraitPoint = m_level + (strengthening * 2);            
        }
    } 

    [NonSerialized]
    short m_level = 0;

    public int exp; // 경험치
    public short model; // 모델 

    public bool isLevelUp;

    public short state; // 상태 
    public short rarity; // 레어도
 

    public short strengthening
    {
        get { return m_Strengthening; }
        set 
        {
            m_Strengthening = value;
            maxTraitPoint = m_level + (m_Strengthening * 2);
        }
    }
    [NonSerialized]
    short m_Strengthening; // 캐릭터 강화도


    public int traitPoint; // 남은 특성 포인트   
    
    
    public short[] traits; // 특성아이디   
    public short[] traitLevels // 특성레벨 
    {
        get { return m_TraitLevels; }
        set
        {
            m_TraitLevels = value;
            m_Stat.level = -1; // 계산에 사용된 레벨 변경하여 하위 함수 진행하도록
            CalcUnitStat_NoneReturn();
        }
    }
    short[] m_TraitLevels;
    public short skin; // 현재스킨
    public Item rightItem; // 오른손 장비
    public Item leftItem; // 왼손 장비
    public short strengCount; // 강화횟수
    public short strengFailCount; // 강화실패 횟수    

    [NonSerialized]
    public bool IsSelected = false;

    [NonSerialized]
    public UnitStat m_StatWithItem = new UnitStat();        // 아이템 효과 반영

    [NonSerialized]
    public UnitStat m_Stat = new UnitStat();                // 아이템 효과 미반영

    [NonSerialized]
    public int maxTraitPoint; // 최대 특성 포인트

    public int GetTraitGrow(AptitudeID aptitudeID)
    {
        int growValue = 0;
        for (int i = 0; i < traits.Length; i++)
        {
            DTrait trait = GameData.Inst.GetTrait(traits[i]);
            if (trait != null)
            {
                if (trait.effStat1 == (int)aptitudeID)
                {
                    growValue += trait.modStat1 * traitLevels[i];
                    //Debug.Log(name + "  " + aptitudeID + "  grow1 add " + growValue);
                }
                if (trait.effStat2 == (int)aptitudeID)
                {
                    growValue += trait.modStat2 * traitLevels[i];
                    //Debug.Log(name + "  " + aptitudeID + "  grow2 add " + growValue);
                }
                if (trait.effStat3 == (int)aptitudeID)
                {
                    growValue += trait.modStat3 * traitLevels[i];
                    //Debug.Log(name + "  " + aptitudeID + "  grow3 add " + growValue);
                }
            }
        }
        return growValue;
    }

    public int GetTraitGrow2(AptitudeID_New aptitudeID)
    {      
        int growValue = 0;
        for (int i = 0; i < traits.Length; i++)
        {
            //Debug.Log("== " + i);
            //Debug.Log("traits[i] " + traits[i]);
            //Debug.Log("traitLevels[i] " + traitLevels[i]);

            DTrait trait = GameData.Inst.GetTrait(traits[i]);
            if (trait != null)
            {
                if (trait.effStat1 == (int)aptitudeID)
                {
                    growValue += trait.modStat1 * traitLevels[i];
                    //Debug.Log("1 = " + trait.modStat1 + " / " + traitLevels[i]);
                }
                if (trait.effStat2 == (int)aptitudeID)
                {
                    growValue += trait.modStat2 * traitLevels[i];  
                    //Debug.Log("2 = " + trait.modStat2 + " / " + traitLevels[i]);
                }
                if (trait.effStat3 == (int)aptitudeID)
                {
                    growValue += trait.modStat3 * traitLevels[i];   
                    //Debug.Log("3 = " + trait.modStat3 + " / " + traitLevels[i]);
                }
            }
        }
        return growValue;
    }



    public float CalcStrengthenProbability(MemberModel material)        // 강화 성공확률 공식
    {
        float standard = 0.0f;
        float sinc = 0.0f;
        float add = 0.0f;  

        if(level < 31)       //강화도가 30이하일 때 = (10-(강화도-1)*0.3) / (3+10^( (30-레벨) / 30) )  , 단 최대 0.95
            standard = (10 - ((strengthening - 1) * 0.3f)) / (3 + 10^((30-level)));
        else                 //강화도가 31이상일 때 = 1 / (3+10^( (30-레벨) / 30) ) , 최대 0.25
            standard = 1 / (3 + 10^((30 - level) / 30));
        
        //----------------------

        int equalTrait = 0;         //선택한 길드원과 같은 특성을 가지고 있으면 속성마다 + 0.03 (특성이 최대 5개이므로, 최대 0.15)
        foreach(short a_Trait in traits)
        {
            foreach(short b_Trait in material.traits)
            {
                if(a_Trait == b_Trait)
                    equalTrait++;
            }
        }

        sinc = equalTrait * 0.03f;

        //----------------------
        
        float stFail = Mathf.Min(strengFailCount, 6);   // 6번 실패까지 적용  // 강화에 실패한 횟수 * 0.05,( 최대 6번 실패까지, 즉 0.3)
        add = stFail * 0.05f;

        return standard + sinc + add;
    }

    const int CalssIndexStart = 11;
    const int CalssIndexEnd = 22;


    //void CalcUnitStat_NoneReturn()
    //{        
    //    if (m_Stat.level != level)  //이전에 계산된 레벨이 아닐때만 계산
    //    {
    //        m_Stat.level = level;

    //        bool isHaveCalss = false;
    //        short classId = 0;
    //        short raceId = 0;

    //        foreach (short traitId in traits)
    //        {
    //            if (traitId != 0)
    //            {
    //                if (traitId < CalssIndexStart)  // 종족
    //                {
    //                    raceId = traitId;
    //                }
    //                else if (traitId <= CalssIndexEnd)  // 클래스
    //                {
    //                    classId = traitId;
    //                    isHaveCalss = true;
    //                }
    //            }
    //        }

    //        DBaseCharacter charData = null;
    //        if (isHaveCalss)
    //            charData = GameData.Inst.GetClassData_Old(classId);
    //        else
    //            charData = GameData.Inst.GetRaceData_Old(raceId);

    //        if (charData != null)
    //        {
    //            m_Stat.maxHp = charData.baseHP + (m_Stat.level - 1) * charData.growHP + GetTraitGrow(AptitudeID.HP);
    //            m_Stat.def = charData.baseDef + (m_Stat.level - 1) * charData.growDef + GetTraitGrow(AptitudeID.Def);
    //            m_Stat.resist = charData.baseRes + (m_Stat.level - 1) * charData.GrowRes + GetTraitGrow(AptitudeID.Res);
    //            m_Stat.prior = 150 + GetTraitGrow(AptitudeID.Prior);
    //            m_Stat.atkType = charData.atkType;
    //            m_Stat.atk = charData.baseAtk + (m_Stat.level - 1) * charData.growAtk + GetTraitGrow(AptitudeID.Atk);
    //            m_Stat.critical = 150 + GetTraitGrow(AptitudeID.Cri);
    //            m_Stat.taunt = charData.taunt + GetTraitGrow(AptitudeID.Taunt);
    //            m_Stat.supportAtk = 50 + GetTraitGrow(AptitudeID.SupportAtk);
    //            m_Stat.supportDef = 50 + GetTraitGrow(AptitudeID.SupportDef);
    //        }
    //    }

    //    m_StatWithItem = m_Stat;

    //    AddItemEffectToStat();      // 이펙트 효과 m_StatWithItem 에 반영
    //}

    //void AddItemEffectToStat()
    //{
    //    Dictionary<AptitudeID, int> effect = new Dictionary<AptitudeID, int>();
        

    //    if (rightItem != null)
    //    {           
    //        if (rightItem.itemInfo.effectType1 != 0)
    //        {
    //            if (effect.ContainsKey((AptitudeID)rightItem.itemInfo.effectType1))
    //                effect[(AptitudeID)rightItem.itemInfo.effectType1] += rightItem.effectValue01;
    //            else
    //                effect.Add((AptitudeID)rightItem.itemInfo.effectType1, rightItem.effectValue01);
    //        }

    //        if (rightItem.itemInfo.effectType2 != 0)
    //        {
    //            if (effect.ContainsKey((AptitudeID)rightItem.itemInfo.effectType2))
    //                effect[(AptitudeID)rightItem.itemInfo.effectType2] += rightItem.effectValue02;
    //            else
    //                effect.Add((AptitudeID)rightItem.itemInfo.effectType2, rightItem.effectValue02);
    //        }
    //    }

    //    if (leftItem != null)
    //    {
    //        if (leftItem.itemInfo.part != 3) // 양손무기일경우 오른손 아이템만 참조 (중복 참조 방지)
    //        {
    //            if (leftItem.itemInfo.effectType1 != 0)
    //            {
    //                if (effect.ContainsKey((AptitudeID)leftItem.itemInfo.effectType1))
    //                    effect[(AptitudeID)leftItem.itemInfo.effectType1] += leftItem.effectValue01;
    //                else
    //                    effect.Add((AptitudeID)leftItem.itemInfo.effectType1, leftItem.effectValue01);
    //            }

    //            if (leftItem.itemInfo.effectType2 != 0)
    //            {
    //                if (effect.ContainsKey((AptitudeID)leftItem.itemInfo.effectType2))
    //                    effect[(AptitudeID)leftItem.itemInfo.effectType2] += leftItem.effectValue02;
    //                else
    //                    effect.Add((AptitudeID)leftItem.itemInfo.effectType2, leftItem.effectValue02);
    //            }
    //        }
    //    }

    //    foreach (KeyValuePair<AptitudeID, int> data in effect)
    //    {
    //        switch ((AptitudeID)data.Key)
    //        {
    //            case AptitudeID.HP:
    //                m_StatWithItem.maxHp += data.Value;
    //                break;
    //            case AptitudeID.Def:                   
    //                m_StatWithItem.def += data.Value;
    //                break;
    //            case AptitudeID.Res:
    //                m_StatWithItem.resist += data.Value;
    //                break;
    //            case AptitudeID.Prior:                   
    //                m_StatWithItem.prior += data.Value;
    //                break;
    //            //case AptitudeID.AtkType:        // 타입을 더하진 않을것이므로??
    //            //    m_StatWithItem.maxHp += data.Value;
    //            //    break;
    //            case AptitudeID.Atk:
    //                m_StatWithItem.atk += data.Value;
    //                break;
    //            case AptitudeID.Cri:
    //                m_StatWithItem.critical += data.Value;
    //                break;
    //            case AptitudeID.Taunt:
    //                m_StatWithItem.taunt += data.Value;
    //                break;
    //            case AptitudeID.SupportAtk:
    //                m_StatWithItem.supportAtk += data.Value;
    //                break;
    //            case AptitudeID.SupportDef:
    //                m_StatWithItem.supportDef += data.Value;
    //                break;
    //        }
    //    }
    //}

    void CalcUnitStat_NoneReturn()
    {
        //Debug.Log("name = " + name);

        if (m_Stat.level != level)  //이전에 계산된 레벨이 아닐때만 계산
        { 
            m_Stat.level = level;

            bool isHaveCalss = false;
            short classId = 0;
            short raceId = 0;

            foreach (short traitId in traits)   // 종족이 있으면 종족데이터 없으면 클래스 데이터 이용
            {
                if (traitId != 0)
                {
                    if (traitId < CalssIndexStart)  // 종족
                    {
                        raceId = traitId;
                    }
                    else if (traitId <= CalssIndexEnd)  // 클래스
                    {
                        classId = traitId;
                        isHaveCalss = true;
                    }
                }
            }

            DBaseCharacter_New charData = null;
            if (isHaveCalss)
                charData = GameData.Inst.GetClassData(classId);
            else
                charData = GameData.Inst.GetRaceData(raceId);
         
            if (charData != null)       // 능력치 연산 하드코딩
            {
                DBaseCharacter_New unitStat = new DBaseCharacter_New();

                unitStat.atkType = charData.atkType;               
                unitStat.growAtk = charData.growAtk;
                unitStat.baseAtk = (short)(charData.baseAtk + (level - 1) * charData.growAtk + GetTraitGrow2(AptitudeID_New.baseAtk));
                unitStat.assist = charData.assist;                
                unitStat.growHP = charData.growHP;
                unitStat.baseHP = (short)(charData.baseHP + (level - 1) * charData.HPMod + GetTraitGrow2(AptitudeID_New.baseHP));               
                unitStat.growDef = charData.growDef;
                unitStat.baseDef = (short)(charData.baseDef + (level - 1) * charData.growDef + GetTraitGrow2(AptitudeID_New.baseDef));
                unitStat.init = (short)(charData.init + GetTraitGrow2(AptitudeID_New.init));
                unitStat.taunt = (short)(charData.taunt + GetTraitGrow2(AptitudeID_New.taunt));              
                unitStat.growMelee = charData.growMelee;
                unitStat.melee = (short)(charData.melee + (level - 1) * charData.growMelee + GetTraitGrow2(AptitudeID_New.melee));
                unitStat.growRange = charData.growRange;
                unitStat.range = (short)(charData.range + (level - 1) * charData.growRange + GetTraitGrow2(AptitudeID_New.range));
                unitStat.growMagic = charData.growMagic;
                unitStat.magic = (short)(charData.magic + (level - 1) * charData.growMagic + GetTraitGrow2(AptitudeID_New.magic));
                unitStat.growPulse = charData.growPulse;
                unitStat.pulse = (short)(charData.pulse + (level - 1) * charData.growPulse + GetTraitGrow2(AptitudeID_New.pulse));
                unitStat.growSpecial = charData.growSpecial;               
                unitStat.special = (short)(charData.special + (level - 1) * charData.growSpecial + GetTraitGrow2(AptitudeID_New.special));
                unitStat.evade = charData.evade + GetTraitGrow2(AptitudeID_New.evade);
                unitStat.evadeMod = (short)(charData.evadeMod + GetTraitGrow2(AptitudeID_New.evadeMod));
                unitStat.defDamage = (float)(charData.defDamage + GetTraitGrow2(AptitudeID_New.defDamage));
                unitStat.defDamageMod = (short)(charData.defDamageMod + GetTraitGrow2(AptitudeID_New.defDamageMod));
                unitStat.HPMod = (short)(charData.HPMod + GetTraitGrow2(AptitudeID_New.HPMod));
                unitStat.healRate = (short)(charData.healRate + GetTraitGrow2(AptitudeID_New.healRate));
                unitStat.res = (short)(charData.res + GetTraitGrow2(AptitudeID_New.res));
                unitStat.skillRate = (short)(charData.skillRate + GetTraitGrow2(AptitudeID_New.skillRate));
                unitStat.skillRateMod = (short)(charData.skillRateMod + GetTraitGrow2(AptitudeID_New.skillRateMod));
                unitStat.critRate = (short)(charData.critRate + GetTraitGrow2(AptitudeID_New.critRate));
                unitStat.critPower = (short)(charData.critPower + GetTraitGrow2(AptitudeID_New.critPower));
                unitStat.attackAssist = (short)(charData.attackAssist + GetTraitGrow2(AptitudeID_New.attackAssist));
                unitStat.defAssist = (short)(charData.defAssist + GetTraitGrow2(AptitudeID_New.defAssist));
                unitStat.atkInit = (short)(charData.atkInit + GetTraitGrow2(AptitudeID_New.atkInit));
                unitStat.atkCooltime = (float)(charData.atkCooltime + GetTraitGrow2(AptitudeID_New.atkCooltime));
                unitStat.atkCooltimeMod = (short)(charData.atkCooltimeMod + GetTraitGrow2(AptitudeID_New.atkCooltimeMod));
                unitStat.moveTime = (short)(charData.moveTime + GetTraitGrow2(AptitudeID_New.moveTime));
                unitStat.moveTimeMod = (short)(charData.moveTimeMod + GetTraitGrow2(AptitudeID_New.moveTimeMod));
                unitStat.getFromAtk = (short)(charData.getFromAtk + GetTraitGrow2(AptitudeID_New.getFromAtk));
                unitStat.getFromHit = (short)(charData.getFromHit + GetTraitGrow2(AptitudeID_New.getFromHit));
                unitStat.moveSpd = (short)(charData.moveSpd + GetTraitGrow2(AptitudeID_New.moveSpd));
                unitStat.moveSpdMod = (short)(charData.moveSpdMod + GetTraitGrow2(AptitudeID_New.moveSpdMod));
                unitStat.healPower = (float)(charData.healPower + GetTraitGrow2(AptitudeID_New.healPower));
                unitStat.healPowerMod = (short)(charData.healPowerMod + GetTraitGrow2(AptitudeID_New.healPowerMod));

				m_Stat.data = unitStat;

				//4대4를 위한 컨버팅//
				m_Stat.maxHp = unitStat.baseHP;
				m_Stat.def = unitStat.baseDef+unitStat.melee;
				m_Stat.taunt = unitStat.taunt;
				m_Stat.resist = unitStat.baseDef+unitStat.magic;
				m_Stat.prior = 150+unitStat.init;
				if(unitStat.atkType==1 || unitStat.atkType==2)
					m_Stat.atkType=1;
				else
					m_Stat.atkType=2;
				m_Stat.atk = unitStat.baseAtk;
				m_Stat.critical = 150;
				m_Stat.supportAtk = unitStat.assist+unitStat.attackAssist;
				m_Stat.supportDef = unitStat.assist+unitStat.defAssist;

            }
			else
				Debug.LogException(new Exception(string.Format("에러. {0}", (isHaveCalss ? "클래스 아이디 : " + classId : "종족 아이디 : " + raceId))));
        }

        m_StatWithItem = m_Stat;

        AddItemEffectToStat();      // 이펙트 효과 m_StatWithItem 에 반영
    }


    void AddItemEffectToStat()
    {
        Dictionary<AptitudeID_New, int> effect = new Dictionary<AptitudeID_New, int>();


        if (rightItem != null)
        {
            if (rightItem.itemInfo.effectType1 != 0)
            {
                if (effect.ContainsKey((AptitudeID_New)rightItem.itemInfo.effectType1))
                    effect[(AptitudeID_New)rightItem.itemInfo.effectType1] += rightItem.effectValue01;
                else
                    effect.Add((AptitudeID_New)rightItem.itemInfo.effectType1, rightItem.effectValue01);
            }

            if (rightItem.itemInfo.effectType2 != 0)
            {
                if (effect.ContainsKey((AptitudeID_New)rightItem.itemInfo.effectType2))
                    effect[(AptitudeID_New)rightItem.itemInfo.effectType2] += rightItem.effectValue02;
                else
                    effect.Add((AptitudeID_New)rightItem.itemInfo.effectType2, rightItem.effectValue02);
            }
        }

        if (leftItem != null)
        {
            if (leftItem.itemInfo.part != 3) // 양손무기일경우 오른손 아이템만 참조 (중복 참조 방지)
            {
                if (leftItem.itemInfo.effectType1 != 0)
                {
                    if (effect.ContainsKey((AptitudeID_New)leftItem.itemInfo.effectType1))
                        effect[(AptitudeID_New)leftItem.itemInfo.effectType1] += leftItem.effectValue01;
                    else
                        effect.Add((AptitudeID_New)leftItem.itemInfo.effectType1, leftItem.effectValue01);
                }

                if (leftItem.itemInfo.effectType2 != 0)
                {
                    if (effect.ContainsKey((AptitudeID_New)leftItem.itemInfo.effectType2))
                        effect[(AptitudeID_New)leftItem.itemInfo.effectType2] += leftItem.effectValue02;
                    else
                        effect.Add((AptitudeID_New)leftItem.itemInfo.effectType2, leftItem.effectValue02);
                }
            }
        }

        foreach (KeyValuePair<AptitudeID_New, int> data in effect)
        {
			m_StatWithItem.data[data.Key] = (float)Convert.ToDouble(m_StatWithItem.data[data.Key]) + data.Value;
        }
    }


    public UnitStat CalcUnitStat()
    {        
        CalcUnitStat_NoneReturn();
        return m_StatWithItem;
    }

	public DSkills[] GetSkills()
	{
		List<DSkills> skillList = new List<DSkills>();
		foreach (short traitId in traits)
		{
			DSkills skill = GameData.Inst.GetSkill(traitId);
			if(skill!=null)
				skillList.Add (skill);
		}
		return skillList.ToArray();
	}

    public void DataCopy(MemberModel tmodel)
    {
        no = tmodel.no;
        id = tmodel.id;
        name = tmodel.name; // 이름
        level = tmodel.level;
        exp = tmodel.exp;
        model = tmodel.model; // 모델 
        isLevelUp = tmodel.isLevelUp;
        state = tmodel.state; // 상태 
        rarity = tmodel.rarity; // 레어도
        traitPoint = tmodel.traitPoint; // 남은 특성 포인트  


        //for (int i = 0; i < traits.Length; i++)
        //{          
        //    traits[i] = tmodel.traits[i];
        //    traitLevels[i] = tmodel.traitLevels[i];
        //}

        traits = tmodel.traits; // 특성아이디   
        traitLevels = tmodel.traitLevels; // 특성레벨 
        skin = tmodel.skin; // 현재스킨
        rightItem = tmodel.rightItem; // 오른손 장비
        leftItem = tmodel.leftItem; // 왼손 장비
        strengCount = tmodel.strengCount; // 강화횟수
        strengFailCount = tmodel.strengFailCount; // 강화실패 횟수  
        IsSelected = tmodel.IsSelected;
        m_StatWithItem = tmodel.m_StatWithItem;
    }

	public bool HasTrait(int _traitID)
	{
		foreach (short traitId in traits) {
			if(traitId == _traitID)
				return true;
		}
		return false;
	}



    public float ExpPercent()
    {
        int stadardExp = 0;

        if (level > 1)
            stadardExp = GameData.Inst.character[level - 1].charExpAcc;

        int expGap = GameData.Inst.character[level].charExp;

        int extraExp = exp - stadardExp;
       

        float returnValue = (exp - stadardExp) / (float)expGap;


        if (returnValue < 0)
        {
            //Debug.LogError("EXP error -------------------- " + returnValue);
            //Debug.LogError("stadardExp = " + stadardExp);
            //Debug.LogError("expGap = " + expGap);
            //Debug.LogError("extraExp = " + extraExp);
            //Debug.LogError("level = " + level);
            //Debug.LogError("exp = " + exp);

            returnValue = 0;
        }

        if (returnValue > 1)
        {
            //Debug.LogError("EXP error -------------------- " + returnValue);
            //Debug.LogError("stadardExp = " + stadardExp);
            //Debug.LogError("expGap = " + expGap);
            //Debug.LogError("extraExp = " + extraExp);
            //Debug.LogError("level = " + level);
            //Debug.LogError("exp = " + exp);

            returnValue = 1;
        }

        return returnValue;
    }
}

[System.Serializable]
public class UnitStat
{
	public int level;
	public int maxHp;
	public int def;			//방어도
	public int taunt;		//주목도
	public int resist;		//저항
	public int prior;		//우선권
	public int atkType;		//공격타입
	public int atk;			//공격력
	public int critical;
	public int supportAtk;	//공격호응도
	public int supportDef;	//방어호응도

	public DBaseCharacter_New data = new DBaseCharacter_New();

	//public Dictionary<AptitudeID_New, float> dic_UnitStat;

	//public Dictionary<AptitudeID_New, float> UniStat()
	//{
	//	if(dic_UnitStat == null)
	//		dic_UnitStat = new Dictionary<AptitudeID_New, float>();
	//	return dic_UnitStat;
	//}


    public void IncreaseStat(int _targetAtt, int _mod)
	{
		if( _targetAtt < (int)AptitudeID.HP || _targetAtt > (int)AptitudeID.SupportDef)
			return;
		float ratio = _mod / 100.0f;
		AptitudeID apId = (AptitudeID)_targetAtt;
		if(apId== AptitudeID.HP)
			maxHp += (int) (maxHp * ratio);
		else if(apId== AptitudeID.Def)
			def += (int) (def * ratio);
		else if(apId== AptitudeID.Res)
			resist += (int) (resist * ratio);
		else if(apId== AptitudeID.Prior)
			prior += (int) (prior * ratio);
		else if(apId== AptitudeID.Atk)
			atk += (int) (atk * ratio);
		else if(apId== AptitudeID.Cri)
			critical += (int) (critical * ratio);
		else if(apId== AptitudeID.Taunt)
			taunt += (int) (taunt * ratio);
		else if(apId== AptitudeID.SupportAtk)
			supportAtk += (int) (supportAtk * ratio);
		else if(apId== AptitudeID.SupportDef)
			supportDef += (int) (supportDef * ratio);
	}




    // 유아이상 보여주는 순서대로 나열
    static public int EffectIdToStatIndex(int effectType)
    {
        int StatIndex = 0;
        switch ((AptitudeID) effectType)
        {
            case AptitudeID.HP:
                StatIndex = 3;
                break;
            case AptitudeID.Def:
                StatIndex = 4;
                break;
            case AptitudeID.Res:
                StatIndex = 5;
                break;
            case AptitudeID.Prior:
                StatIndex = 7;
                break;
            case AptitudeID.AtkType:
                StatIndex = 0;
                break;
            case AptitudeID.Atk:
                StatIndex = 1;
                break;
            case AptitudeID.Cri:
                StatIndex = 2;
                break;
            case AptitudeID.Taunt:
                StatIndex = 6;
                break;
            case AptitudeID.SupportAtk:
                StatIndex = 8;
                break;
            case AptitudeID.SupportDef:
                StatIndex = 9;
                break;
            default:
                StatIndex = -1;
                break;
        }

        return StatIndex;
    }


    static public int StatIndexToEffectId(int StatIndex)
    {
        int effectType = 0;
        switch (StatIndex)
        {
            case 3:
                effectType = (int)AptitudeID.HP;
                break;
            case 4:
                effectType = (int)AptitudeID.Def;
                break;
            case 5:
                effectType = (int)AptitudeID.Res;
                break;
            case 7:
                effectType = (int)AptitudeID.Prior;
                break;
            case 0:
                effectType = (int)AptitudeID.AtkType;
                break;
            case 1:
                effectType = (int)AptitudeID.Atk;
                break;
            case 2:
                effectType = (int)AptitudeID.Cri;
                break;
            case 6:
                effectType = (int)AptitudeID.Taunt;
                break;
            case 8:
                effectType = (int)AptitudeID.SupportAtk;
                break;
            case 9:
                effectType = (int)AptitudeID.SupportDef;
                break;
            default:
                effectType = -1;
                break;
        }

        return effectType;
    }


    static public int[] Stats(UnitStat tempStat)
    {
        int[] stats = new int[10]
        {
            tempStat.atkType,
            tempStat.atk,
            tempStat.critical,
            tempStat.maxHp,
            tempStat.def,
            tempStat.resist,
            tempStat.taunt,
            tempStat.prior,
            tempStat.supportAtk,
            tempStat.supportDef
        };
        return stats;
    }
}




